package com.test;

public class 深克隆和浅克隆
{
    public static void main(String[] args) throws CloneNotSupportedException
    {
        Person p = new Person(20, "m");
        Person p1 = (Person) p.clone();
        System.out.println(p1.getName() == p.getName());
        System.out.println(p1 == p);
    }

}

class Person implements Cloneable
{
    private int age;
    private String name;

    @Override
    protected Object clone() throws CloneNotSupportedException
    {
        return (Person) super.clone();
    }

    @Override
    public String toString()
    {
        return "Person{" + "age=" + age + ", name='" + name + '\'' + '}';
    }

    public int getAge()
    {
        return age;
    }

    public void setAge(int age)
    {
        this.age = age;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Person(int age, String name)
    {
        this.age = age;
        this.name = name;
    }
}
